package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.druid.util.StringUtils;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class PostCodeRequest extends Request {
	
	private String areaCode;
	private String address;

	public String getAreaCode() {
		return areaCode;
	}

	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		
		//获取邮编信息
		String areaCode = requestInfo.getParameter(ApiUrlParamEnum.areaCode.getParamName());
		String address = requestInfo.getParameter(ApiUrlParamEnum.address.getParamName());
		if(StringUtils.isEmpty(areaCode) || StringUtils.isEmpty(address)) {
			throw new RequestIllegalException("缺少必要参数，请确认");
		}
		if(areaCode.length() > 6) {
			throw new RequestIllegalException("错误的参数，请确认");
		}
		setAddress(address);
		setAreaCode(areaCode);
	}

}
